package com.stm.web.controller.basicData;

import java.util.List;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.stm.basicData.domain.KfToolsTestProject;
import com.stm.basicData.domain.KfToolsType;
import com.stm.basicData.domain.ToolsTestOption;
import com.stm.basicData.service.IToolsTestOptionService;
import com.stm.basicData.service.KfToolsTestProjectService;
import com.stm.basicData.service.KfToolsTypeService;
import com.stm.common.annotation.Log;
import com.stm.common.core.controller.BaseController;
import com.stm.common.core.domain.AjaxResult;
import com.stm.common.core.page.TableDataInfo;
import com.stm.common.enums.BusinessType;
import com.stm.common.utils.poi.ExcelUtil;
import com.stm.framework.util.ShiroUtils;

/**
 * 工具试验项目
 * 
 * @author wyc
 * @date 2019-04-08
 */
@Controller
@RequestMapping("/basicData/toolsTestOption")
public class ToolsTestOptionController extends BaseController
{
    private String prefix = "basicData/toolsTestOption";
	
	@Autowired
	private IToolsTestOptionService toolsTestOptionService;
	@Autowired
	private KfToolsTestProjectService kfToolsTestProjectService;

	@Autowired
	private KfToolsTypeService kfToolsTypeService;

	@RequiresPermissions("basicData:toolsTestOption:view")
	@GetMapping()
	public String toolsTestOption(ModelMap mmap)
    {
    	mmap.put("user", ShiroUtils.getSysUser());
	    return prefix + "/toolsTestOption";
	}
	
	/**
	 * 查询工具试验列表
	 */
	@RequiresPermissions("basicData:toolsTestOption:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(ToolsTestOption toolsTestOption)
	{
		startPage();
        List<ToolsTestOption> list = toolsTestOptionService.selectToolsTestOptionList(toolsTestOption);
		return getDataTable(list);
	}

	/**
	 * 初始化下拉列表数据
	 * 查询出所有工具类型
	 */
	@PostMapping("/initToolsType")
	@ResponseBody
	public List<KfToolsType> initToolsType(KfToolsType toolsType)
	{
		return  kfToolsTypeService.selectAllPageList(toolsType);
	}

	/**
	 * 导出工具试验列表
	 */
	@RequiresPermissions("basicData:toolsTestOption:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ToolsTestOption toolsTestOption)
    {
    	List<ToolsTestOption> list = toolsTestOptionService.selectToolsTestOptionList(toolsTestOption);
        ExcelUtil<ToolsTestOption> util = new ExcelUtil<ToolsTestOption>(ToolsTestOption.class);
        return util.exportExcel(list, "toolsTestOption");
    }
	
	/**
	 * 新增工具试验
	 */
	@GetMapping("/add")
	public String add()
	{
		return prefix + "/add";
	}
	
	/**
	 * 新增保存工具试验
	 */
	@RequiresPermissions("basicData:toolsTestOption:add")
	@Log(title = "工具试验", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(@RequestBody ToolsTestOption toolsTestOption)
	{
		toolsTestOption.setCreateBy(ShiroUtils.getLoginName());
		toolsTestOption.setDprtcode(ShiroUtils.getSysUser().getDeptId());
		return toAjax(toolsTestOptionService.insertToolsTestOption(toolsTestOption));
	}

	/**
	 * 修改工具试验
	 */
	@GetMapping("/edit/{id}")
	public String edit(@PathVariable("id") String id, ModelMap mmap)
	{
		ToolsTestOption toolsTestOption = toolsTestOptionService.selectToolsTestOptionById(id);
		mmap.put("toolsTestOption", toolsTestOption);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存工具试验
	 * @throws Exception 
	 */
	@RequiresPermissions("basicData:toolsTestOption:edit")
	@Log(title = "工具试验", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(@RequestBody ToolsTestOption toolsTestOption) throws Exception
	{
		toolsTestOption.setUpdateBy(ShiroUtils.getLoginName());
		return toAjax(toolsTestOptionService.updateToolsTestOption(toolsTestOption));
	}
	
	/**
	 * 删除工具试验
	 * @throws Exception 
	 */
	@RequiresPermissions("basicData:toolsTestOption:remove")
	@Log(title = "工具试验", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids) throws Exception
	{		
		return toAjax(toolsTestOptionService.deleteToolsTestOptionByIds(ids));
	}
	
	
    /**
     * 
     * @Description 查看详情
     * @CreateTime 2019年4月8日 上午9:42:17
     * @CreateBy 林龙
     * @param id
     * @param mmap
     * @return
     */
    @GetMapping("/detail/{id}")
    public String detail(@PathVariable("id") String id, ModelMap mmap)
    {
    	ToolsTestOption toolsTestOption = toolsTestOptionService.selectToolsTestOptionById(id);
		mmap.put("toolsTestOption", toolsTestOption);
        return prefix + "/details";
    }
	
	/**
	 * 试验项目列表
	 */
	@PostMapping("/projectList")
	@ResponseBody
	public TableDataInfo projectList(KfToolsTestProject kfToolsTestProject)
	{
		startPage();
        List<KfToolsTestProject> list = kfToolsTestProjectService.selectAllPageList(kfToolsTestProject);
		return getDataTable(list);
	}
	
	
}
